﻿<CustomWindow:EssentialWindow 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
    xmlns:CustomWindow="clr-namespace:CustomWindow;assembly=CustomWindow"
  mc:Ignorable="d" 
  xmlns:TwitterLib="clr-namespace:TwitterLib;assembly=TwitterLib" 
  xmlns:Pawing="clr-namespace:Pawing" 
  xmlns:controls="clr-namespace:Common.Controls;assembly=Common" 
  xmlns:converters="clr-namespace:Common.Converters;assembly=Common"
  xmlns:r="clr-namespace:PixelLab.Wpf;assembly=PixelLab.Wpf"
    xmlns:t="clr-namespace:PixelLab.Wpf.Transitions;assembly=PixelLab.Wpf"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:Search="clr-namespace:Pawing.Controls.Search"
  AllowsTransparency="True" Background="Transparent" 
  ResizeMode="NoResize" Topmost="True"
  x:Class="Pawing.DesktopWindow"
  Title="Pawing 2.0" 
  WindowStyle="None"
  Width="580" Height="700" MinWidth="200" MinHeight="200" 
        Loaded="DesktopWindow_Loaded">
        <CustomWindow:EssentialWindow.Resources>
        <ResourceDictionary>
            <!-- Placed storyboard animations in their own file to condense the markup -->
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources\Storyboards.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <Storyboard x:Key="CloseAnimation" Completed="CloseAnimation_Completed">
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="DesktopWindowGrid" Storyboard.TargetProperty="(UIElement.Opacity)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00.0000000" Value="1"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>
            <converters:CharRemainingValueConverter x:Key="CharRemainingConverter" />
            <converters:CharRemainingForegroundColorConverter x:Key="CharRemainingColorConverter" />
        </ResourceDictionary>
    </CustomWindow:EssentialWindow.Resources>

    <CustomWindow:EssentialWindow.Triggers>
        <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="Update">
            <BeginStoryboard Storyboard="{StaticResource UpdateMouseEnter}" x:Name="UpdateMouseEnter_BeginStoryboard" />
        </EventTrigger>
        <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="Update">
            <BeginStoryboard Storyboard="{StaticResource UpdateMouseLeave}" x:Name="UpdateMouseLeave_BeginStoryboard" />
        </EventTrigger>
    </CustomWindow:EssentialWindow.Triggers>
    <Grid x:Name="DesktopWindowGrid">
        <Border x:Name="ContentBorder" BorderBrush="#55FFFFFF" BorderThickness="1" CornerRadius="5"  Margin="252,191,-1,-1" Opacity="0.0" Visibility="Collapsed" d:IsLocked="True">
            <DockPanel x:Name="LayoutRoot">
                <!-- Header -->
                <Border DockPanel.Dock="Top" Height="40" Padding="10,0,10,0" CornerRadius="5,5,0,0" x:Name="Header" MouseMove="Header_MouseMove" Background="{DynamicResource PrimaryBackgroundBrush}" Margin="-1,0,1,0">
                    <DockPanel LastChildFill="False">
                        <TextBlock Text="Pawing" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="18" FontWeight="Bold" Foreground="{DynamicResource HeaderForegroundBrush}" />
                        <Border x:Name="WindowButtonsPlaceholder" Visibility="Collapsed" HorizontalAlignment="Right" VerticalAlignment="Top" DockPanel.Dock="Right" Margin="0" />
                        <Button Content="隐藏" Height="15" x:Name="OptionsButton" Click="OptionsButton_Click" MinWidth="25" MinHeight="20" FontSize="9" DockPanel.Dock="Right" Margin="0,0,5,0" Width="50" ToolTip="隐藏窗口" />
                        <Button Content="刷新" Height="15" x:Name="RefreshButton" Click="RefreshButton_Click" MinWidth="25" MinHeight="20" FontSize="9" DockPanel.Dock="Right" Margin="0,0,10,0" Width="50" ToolTip="更新" />
                        <ToggleButton Content="Filter" Height="25" x:Name="FilterToggleButton" MinWidth="25" MinHeight="20" FontSize="9" IsEnabled="True" Width="55" ToolTip="显示过滤界面" DockPanel.Dock="Right" BorderThickness="1,1,1,1" Margin="0,0,10,0" IsChecked="False" Unchecked="FilterToggleButton_Unchecked" Background="{DynamicResource NormalBrush}" Foreground="{DynamicResource LightBrush}" BorderBrush="{DynamicResource NormalBorderBrush}" Visibility="Visible">
                            <ToggleButton.Clip>
                                <RectangleGeometry Rect="3,3,50,20" RadiusX="5" RadiusY="5" />
                            </ToggleButton.Clip>
                        </ToggleButton>
                    </DockPanel>

                </Border>
                <!-- Filter  -->
                <Border DockPanel.Dock="Top" x:Name="Filter" Background="#FFCEE8B9" IsEnabled="True">
                    <r:Reveal 
  			VerticalReveal="FromTopToBottom" 
  			IsExpanded="{Binding IsChecked, ElementName=FilterToggleButton}" HorizontalAlignment="Left">
                        <DockPanel Margin="0,0,5,5" VerticalAlignment="Stretch">
                            <Label Content="Filter" Target="{Binding ElementName=FilterTextBox, Mode=OneWay}"/>
                            <controls:FilterText x:Name="FilterTextBox" TextBoxBase.TextChanged="FilterTextBox_TextChanged" Width="150"/>
                            <Button Content="Search with TweetScan" Height="20" Margin="10,0,0,0" x:Name="TweetScanButton" FontSize="9" Click="TweetScanButton_Click" Visibility="Collapsed"/>
                        </DockPanel>
                    </r:Reveal>
                </Border>
                <!-- StatusBar-->
                <Border DockPanel.Dock="Bottom" Padding="5,2,0,2" CornerRadius="0,0,5,5" Background="{DynamicResource StatusBackgroundBrush}" x:Name="StatusBar">
                    <DockPanel>
                        <TextBlock DockPanel.Dock="Left" x:Name="StatusTextBlock" TextWrapping="NoWrap" Foreground="#FFE4E4E4" Text="Login" TextTrimming="CharacterEllipsis" />
                    </DockPanel>
                </Border>
				<!--Content-->
                <Grid x:Name="ContentHolder">
                    <!-- User -->
                    <Grid x:Name="UserTimeline" Visibility="Collapsed">
                        <DockPanel>
                            <Border DockPanel.Dock="Top" BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="0,0,0,1">
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FFD0DBE7" Offset="0" />
                                        <GradientStop Color="#FFFFFFFF" Offset="1" />
                                    </LinearGradientBrush>
                                </Border.Background>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="80" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <Grid VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,12,0,0" Width="58" Height="60">
                                        <aero:SystemDropShadowChrome CornerRadius="5,5,5,5">
                                            <Rectangle Stroke="#FF8E8E8E" RadiusX="10" RadiusY="5">
                                                <Rectangle.Fill>
                                                    <LinearGradientBrush EndPoint="0.869,0.837" StartPoint="0.278,0.298">
                                                        <GradientStop Color="#FFFFFFFF" Offset="0"/>
                                                        <GradientStop Color="#FF7BB2B7" Offset="1"/>
                                                    </LinearGradientBrush>
                                                </Rectangle.Fill>
                                            </Rectangle>
                                        </aero:SystemDropShadowChrome>
                                        <Border BorderBrush="{DynamicResource ImageBorderBrush}" BorderThickness="1,1,1,1" Margin="4,5,4,5" CornerRadius="2,2,2,2">
                                            <Image Width="48" Height="48" Source="{Binding User.ImageUrl}" x:Name="UserImage" />
                                        </Border>
                                    </Grid>
                                    <Grid Grid.Column="1" Margin="0,10,0,0">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="*" />
                                        </Grid.RowDefinitions>
                                        <TextBlock Text="{Binding User.FullName, FallbackValue=Full Name}" FontWeight="Bold" FontSize="16" x:Name="FullName" Cursor="Hand" MouseLeftButtonUp="ScreenName_MouseLeftButtonUp" Tag="{Binding User.TwitterUrl, Mode=Default}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" ToolTip="{Binding User.TwitterUrl, Mode=Default}" d:LayoutOverrides="Width, Height" />
                                        <DockPanel Grid.Row="1">
                                            <TextBlock x:Name="Description" Text="{Binding User.Description, Mode=Default, FallbackValue=Description}" TextWrapping="Wrap" FontStyle="Italic" DockPanel.Dock="Top" />
                                            <TextBlock x:Name="SiteUrl" Text="{Binding User.SiteUrl, Mode=Default, FallbackValue=Site Url}" TextWrapping="NoWrap" MouseLeftButtonUp="Url_MouseLeftButtonUp" Cursor="Hand" TextTrimming="CharacterEllipsis" DockPanel.Dock="Top" ToolTip="{Binding User.SiteUrl, Mode=Default}" TextDecorations="Underline" Foreground="#FF0000FF"><Hyperlink NavigateUri="{Binding User.SiteUrl, Mode=Default, FallbackValue=Site Url}" /></TextBlock>
                                            <TextBlock x:Name="Location" Text="{Binding User.Location, Mode=Default, FallbackValue=Location}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" />
                                        </DockPanel>
                                    </Grid>
                                </Grid>
                            </Border>
                            <ListBox  x:Name="UserTimelineListBox" ScrollViewer.ScrollChanged="UserTimelineListBox_ScrollChanged" ItemsSource="{Binding Mode=OneWay}" ScrollViewer.CanContentScroll="False" IsSynchronizedWithCurrentItem="True" ItemTemplate="{DynamicResource UserTimeLineTemplate}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" MouseLeftButtonUp="TweetsListBox_MouseLeftButtonUp" MouseRightButtonUp="UserTimelineListBox_MouseRightButtonUp" BorderThickness="0,0,0,0" DockPanel.Dock="Bottom" 
              controls:TweetTextBlock.NameClick="NameClickedInTweet"
              controls:TweetTextBlock.HashtagClick="HashtagClickedInTweet">
                                <ListBox.ContextMenu>
                                    <ContextMenu x:Name="UserContextMenu">
                                        <MenuItem Header="转发" Click="ContextMenuRetweet_Click"/>
                                        <MenuItem Header="关注" Click="ContextMenuFollow_Click" IsEnabled="True"/>
                                        <MenuItem Header="发送私信" Click="ContextMenuDirectMessage_Click"/>
                                        <MenuItem Header="删除" Click="ContextMenuDelete_Click" IsEnabled="True"/>
                                        <MenuItem Header="回复" Click="ContextMenuRetweet_Click" IsEnabled="True"/>
                                        <MenuItem Header="查看回复" Click="ContextMenuConversation_Click"/>
                                        <MenuItem Header="刷新" Click="RefreshButton_Click"/>
                                        <MenuItem Header="清除所有微博" Click="ContextMenuClear_Click"/>
                                    </ContextMenu>
                                </ListBox.ContextMenu>
                            </ListBox>
                        </DockPanel>
                        <Border Height="21" Background="{StaticResource UpdateBackgroundBrush}" VerticalAlignment="Bottom" Padding="2,0" x:Name="Update" MouseLeftButtonUp="Update_MouseLeftButtonUp" BorderBrush="{DynamicResource PrimaryBackgroundBrush}" BorderThickness="0,0,0,1" ToolTip="显示发布界面">
                            <DockPanel OpacityMask="#FF000000" x:Name="dockPanel">
                                <TextBlock HorizontalAlignment="Center" DockPanel.Dock="Top" Text="我要说" TextWrapping="Wrap" VerticalAlignment="Top" x:Name="UpdateTextBlock" Margin="0,2,0,0" />
                                <Grid Margin="0,2,0,0" KeyboardNavigation.TabNavigation="Cycle">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="152*" />
                                        <ColumnDefinition Width="49*" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <Grid Grid.ColumnSpan="2">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" MaxWidth="100"/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        <TextBox Grid.Column="1" Text="" TextWrapping="Wrap" x:Name="TweetTextBox" SpellCheck.IsEnabled="True" ToolTip="Enter tweet (140 character limit)" PreviewKeyDown="TweetTextBox_PreviewKeyDown" 
                                          DataObject.Pasting="TweetTextBox_OnPaste" TextChanged="TweetTextBox_TextChanged" Height="66" TabIndex="1" AllowDrop="True" PreviewDragEnter="Recent_PreviewDragOver" PreviewDragOver="Recent_PreviewDragOver" PreviewDrop="Recent_Drop" />
                                        <TextBlock Grid.Column="1" Text="{Binding Text, Converter={StaticResource CharRemainingConverter}, ElementName=TweetTextBox, Mode=Default}" FontSize="18" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,5,8" FontFamily="Georgia" x:Name="CharRemainingCounter" Foreground="{Binding Text.Length, Converter={StaticResource CharRemainingColorConverter}, ElementName=TweetTextBox}" />

                                        <r:Reveal 
  			VerticalReveal="FromTopToBottom" 
  			IsExpanded="{Binding ElementName=imagePresenter, Path=IsVisible}" HorizontalAlignment="Left">
                                            <Image Grid.Column="0" x:Name="imagePresenter" ToolTip="点击删除图片" Margin="0,0,2,0" Opacity="0.4"  MaxHeight="66" Stretch="Uniform" MouseEnter="imagePresenter_MouseEnter"  HorizontalAlignment="Left" MouseLeave="imagePresenter_MouseLeave" MouseLeftButtonUp="imagePresenter_MouseLeftButtonUp" />
                                        </r:Reveal>
                                    </Grid>
                                    <Button Width="75" Height="23" VerticalAlignment="Bottom" Content="发布" Grid.Column="2" x:Name="UpdateButton" Click="UpdateButton_Click" Margin="10,0,5,55" IsDefault="True" ToolTip="Submit update" TabIndex="2" HorizontalAlignment="Right" />
                                    <Button Width="75" Height="23" VerticalAlignment="Bottom" Content="表情" Grid.Column="2" x:Name="AddEmotButton" Margin="10,0,5,30" IsDefault="True" ToolTip="添加表情" TabIndex="3" HorizontalAlignment="Right" Click="AddEmotButton_Click" />
                                    <Button Width="75" Height="23" VerticalAlignment="Bottom" Content="图片" Grid.Column="2" x:Name="AddPicButton" Margin="10,0,5,5" IsDefault="True" ToolTip="添加图片" TabIndex="4" Click="AddPicButton_Click" HorizontalAlignment="Right" />
                                    <Button Width="75" Height="23" VerticalAlignment="Bottom" Content="Cancel" Grid.Column="2" x:Name="CancelButton" Click="CancelButton_Click" Margin="10,0,5,5" ToolTip="Clear text and hide update panel" TabIndex="5" Visibility="Collapsed" HorizontalAlignment="Right" d:IsHidden="True" />
                                </Grid>
                            </DockPanel>
                        </Border>
                    </Grid>
                    <!--DirectMessage-->
                    <Grid x:Name="Messages" Visibility="Collapsed">
                            <ListBox x:Name="MessagesListBox" BorderThickness="0,0,0,0" Margin="0,0,0,125"
                                     ScrollViewer.ScrollChanged="MessagesListBox_ScrollChanged" ScrollViewer.CanContentScroll="False" IsSynchronizedWithCurrentItem="True"  ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                     ItemTemplate="{DynamicResource MessagesTemplate}" ItemsSource="{Binding Mode=OneWay}"
                                     MouseLeftButtonUp="MessagesListBox_MouseLeftButtonUp"  PreviewMouseLeftButtonDown="MessagesListBox_PreviewMouseLeftButtonDown"
              controls:TweetTextBlock.NameClick="NameClickedInTweet"
              controls:TweetTextBlock.HashtagClick="HashtagClickedInTweet" >
                                <ListBox.ContextMenu>
                                    <ContextMenu x:Name="MessagesContextMenu">
                                        <MenuItem Header="转发" Click="ContextMenuRetweet_Click"/>
                                        <MenuItem Header="发送私信" Click="ContextMenuDirectMessage_Click"/>
                                        <MenuItem Header="删除" Click="ContextMenuDeleteMessage_Click" IsEnabled="True"/>
                                        <MenuItem Header="回复" Click="ContextMenuRetweet_Click" IsEnabled="True"/>
                                    </ContextMenu>
                                </ListBox.ContextMenu>
                            </ListBox>
                            <Border DockPanel.Dock="Bottom" Height="125" Background="{StaticResource UpdateBackgroundBrush}" VerticalAlignment="Bottom" Padding="10,0,10,0" x:Name="Message" BorderBrush="{DynamicResource PrimaryBackgroundBrush}" BorderThickness="0,0,0,1" CornerRadius="0,0,5,5" >
                                <DockPanel OpacityMask="#FF000000" x:Name="MessageDockPanel">
                                    <TextBlock HorizontalAlignment="Center" DockPanel.Dock="Top" Text="发私信" TextWrapping="Wrap" VerticalAlignment="Top" x:Name="MessageTextBlock" Margin="0,2,0,0" />
                                    <Grid Margin="0,5,0,0">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="*" />
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="To:" TextWrapping="Wrap" Margin="0,0,5,0" VerticalAlignment="Center" />
                                            <TextBox Text="" TextWrapping="Wrap" IsEnabled="False" VerticalAlignment="Center" Width="120" Margin="0,0,0,2" x:Name="MessageUserTextBox" />
                                        </StackPanel>
                                        <TextBox Grid.Row="1" Text="" TextWrapping="Wrap" x:Name="MessageTextBox" SpellCheck.IsEnabled="True" Margin="0,0,0,2" />
                                        <TextBlock	Grid.Row="1" 
								Text="{Binding Text, Converter={StaticResource CharRemainingConverter}, ElementName=MessageTextBox, Mode=Default}" 
								FontSize="18" 
								VerticalAlignment="Bottom" 
								HorizontalAlignment="Right" 
								Margin="0,0,5,8" 
								FontFamily="Georgia" 
								x:Name="MessageCharRemainingCounter"
								Foreground="{Binding Text.Length, Converter={StaticResource CharRemainingColorConverter}, ElementName=MessageTextBox}" />

                                    <Button Width="60" Height="23" VerticalAlignment="Bottom"  Margin="10,0,0,4"  Content="表情" Grid.Column="1" Grid.Row="1" x:Name="MessageAddEmotButton" IsDefault="True" ToolTip="添加表情" TabIndex="3" Click="AddEmotButton_Click" />
                                    <Button  Width="60" Height="23" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="10,0,0,30" Content="发送" Grid.Column="1" Grid.Row="1" x:Name="SendMessageButton" Click="SendMessageButton_Click" IsDefault="True" />
                                    </Grid>
                                </DockPanel>
                            </Border>
                        </Grid>
                </Grid>
            </DockPanel>
        </Border>
        <Border x:Name="MainBorder" Margin="0" Cursor="Hand">
            <Grid Margin="0">
                <Grid Name="iconGrid" HorizontalAlignment="Left" Height="200" VerticalAlignment="Top" Width="200" Margin="193,174,0,0" Opacity="0.0"
                       MouseLeave="iconGrid_MouseLeave" MouseEnter="iconGrid_MouseEnter">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="100"/>
                        <RowDefinition Height="100"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition Width="100"/>
                    </Grid.ColumnDefinitions>
                    <Image Name="closeIcon" Grid.Row="0" Grid.Column="1" Source="close.png" MouseLeftButtonUp="closeIcon_MouseLeftButtonUp"/>
                    <Image Name="userTimelineIcon" Grid.Row="1" Grid.Column="1" Source="home.png" MouseLeftButtonUp="userTimelineIcon_MouseLeftButtonUp"/>
                    <Image Name="messageIcon" Grid.Row="0" Grid.Column="0" Source="message.png" MouseLeftButtonUp="messageIcon_MouseLeftButtonUp"/>
                    <Image Name="recommendIcon" Grid.Row="1" Grid.Column="0" Source="recommend.png" MouseLeftButtonUp="recommendIcon_MouseLeftButtonUp"/>
                </Grid>
                <Grid x:Name="AvatarGrid" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="264,244,0,0" Width="58" Height="60" MouseLeftButtonDown="AvatarGrid_MouseLeftButtonDown" d:IsLocked="True">
            	 	<aero:SystemDropShadowChrome CornerRadius="5,5,5,5">
            	 		<Rectangle Stroke="#FF8E8E8E" RadiusX="10" RadiusY="5">
            	 			<Rectangle.Fill>
            	 				<LinearGradientBrush EndPoint="0.869,0.837" StartPoint="0.278,0.298">
            	 					<GradientStop Color="#FFFFFFFF" Offset="0"/>
            	 					<GradientStop Color="#FF7BB2B7" Offset="1"/>
            	 				</LinearGradientBrush>
            	 			</Rectangle.Fill>
            	 		</Rectangle>
            	 	</aero:SystemDropShadowChrome>
            	 	<Border BorderBrush="{DynamicResource ImageBorderBrush}" BorderThickness="1,1,1,1" Margin="4,5,4,5" CornerRadius="2,2,2,2">
            	 		<Image Width="48" Height="48" Source="{Binding User.ImageUrl}" x:Name="MainUserImage" />
            	 	</Border>
            	 </Grid>
            	 </Grid>
        </Border>
    </Grid>
</CustomWindow:EssentialWindow >
